<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
<meta content="telephone=no" name="format-detection" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<title>兴业云支付</title>
<link type="text/css" rel="stylesheet" href="../../resource/fapiao.css">
<link rel="stylesheet" href="../../resource/weui.min.css" />
<link rel="stylesheet" href="../../resource/example.css" />

<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../resource/jweixin-1_002.js"></script>
<script type="text/javascript" src="../../resource/jweixin-1.js"></script>
<script src="../../resource/jquery-1.js"></script>
<script src="../../resource/qrcode.js"></script>
<script src="../../resource/jquery-barcode.js"></script>

<link rel="stylesheet" href="../../resource/jinsuistyle.css" />
<script type="text/javascript">
		var openid = '';
		apiready = function(){
			openid = $api.getStorage('openid');
			var header = $api.byId('jsheader');
			if(api.systemType=='ios'){
				$api.fixIos7Bar(header);
			}
//			else{
//				$api.fixStatusBar(header);
//			}

			$api.setStorage('state','000');
		}

			function scanQRCode(){
				var FNScanner = api.require('FNScanner');
				FNScanner.openScanner({
  				  autorotation: true
				}, function(ret, err) {
					//alert(JSON.stringify(ret));
  				  if (ret) {
  				  		//alert(JSON.stringify(ret.content));
  				  		if(ret.eventType=="success"){
   				     			var strs = ret.content.split("&");
                      	 	 	var parms = "";
                      	 	 for(var i=0;i<strs.length;i++){
                      	 	     if(strs[i].indexOf("invoiceMerId") == 0){
                        		        parms += "&" +  strs[i];
                        		    }
                        		    if(strs[i].indexOf("terminalId") == 0){
                        		        parms += "&" + strs[i];
                        		    }
                       		 }
                       		 if(parms == ""){
                       		     //alert("没有扫描到相关信息！");
                       		    api.alert({msg:'没有扫描到相关信息！'});
                       		 }else{
//                     		 	api.openWin({
//	                                    name: 'chs',
//	                                    url: './Invoice_chs.html',
//	                                    pageParam:{
//	                                    	codeStr : openid.replace(/\+/g, '%2B') + '&scaned=0' + parms.replace(/\+/g, '%2B')
//	                                    }
//                                  });

									api.ajax({
						    			url: 'http://wechat.scjinsui.com/weixin/fpkj/postKp0.do?'+parms.replace("invoiceMerId","invoicemerid").replace("terminalId","terminalid"),
						    			method: 'post'
									}, function(ret, err) {
						   			 if (ret) {
						   			 	 if(ret.msg=="OK"){
							           			//window.location.href="<%=basePath %>wx/Pay_success.jsp?msgType=2";
							           			api.openWin({
							                           name: 'success',
							                           url: './Pay_success.html',
							                               pageParam:{
							                               		msgType : '2'
							                               }
						                           });
								           	}else{
								           		api.openWin({
							                           name: 'failed',
							                           url: './Pay_failed.html',
							                               pageParam:{
							                               		msgType : '2'
							                               }
						                           });
								           	}
							        	   $("#loadingToast").hide();
						   			 } else {
						   			     console.log('服务请求错误,请联系管理员...');
						   			     api.alert({msg:'网络异常'});
						   			 }
									});







                                    
                                    
                                    
                       		 }
                       	 }
   				 } else {
   				     alert(JSON.stringify(err));
   				 }
				});
			}

            var mytime = null;
    		function createQrcode(){
    			$("#bcTarget").empty();
    			$("#invoiceName").empty();
    			$(".shade").show();
    			if(mytime != null){
    				clearTimeout(mytime);
    			}
    			var num = 0;
    			var fwqTime ="";
    			var orderid ="";
    			$("#loadingToast").show();
    			api.ajax({
    				url: 'http://wechat.scjinsui.com/weixin/fpkj/orderid.do',
  				  method: 'post',
   				 data: {
    				    values: {
    				        openid: openid
     				   }
    				}
				}, function(ret, err) {
    				if (ret) {
    				    if(ret.msg != "OK"){
    				    		$("#loadingToast").hide();
    				    		api.alert({msg:'数据加载失败...'});
    				    		$(".shade").hide();
    				    		return;
    				    	}
    				    		orderid = ret.orderid;
    				    		fwqTime = ret.time;
    				    		$("#loadingToast").hide();
    				    		$("#bcTarget").empty().barcode(orderid, "code93",{barWidth:2, barHeight:60,showHRI:false});
    				    		var info = "openid=" + openid + "&time=" + fwqTime + "&orderid=" + orderid ;
    							var qrcode = new QRCode("invoiceName", {
    							    text : info,
    							    width: 200,
    							    height: 200,
    							    colorDark : "#000000",
    							    colorLight : "#ffffff",
    							    correctLevel : QRCode.CorrectLevel.H
    							});
    							mytime = setInterval(function(){
    								num ++ ;
    								//$("#bbb").html(num);
    								if(num > 20){
    									clearTimeout(mytime);
    									api.alert({msg:'对不起，二维码和条形码已经过期！'});
    									//alert("对不起，二维码和条形码已经过期！");
    									$(".shade").hide();
    								}
    								api.ajax({
    									url: 'http://wechat.scjinsui.com/weixin/fpkj/orderInfo.do',
    									method: 'post',
    									data: {
     									   values: {
       									     orderid: orderid
       									 }
    									}
									}, function(ret, err) {
   										 if (ret) {
     									   if (ret.msg == "OK") {
												if (ret.STATUS == "1") {
													api.ajax({
   														url: 'https://pay.swiftpass.cn/pay/jspay',
    															method: 'post',
    																data: {
      																	values: {
      																	   showwxpaytitle: '1',
      																	   token_id : ret.TOKEN_ID
       																		 }
    																}
																}, function(ret, err) {
   																			 if (ret) {
   																			     api.alert({ msg: '1' });
   																				 } else {
    																		api.alert({msg:'网络异常'});
    																	}
																		});
																clearTimeout(mytime);
															}  else if (ret.STATUS == "-1") {
																api.alert({msg:'下单失败！'});
																$(".shade").hide();
																clearTimeout(mytime);
															} else if (ret.STATUS == "-2") {
																api.alert({msg:'订单超时！'});
																$(".shade").hide();
																clearTimeout(mytime);
															}
														}
   									 } else {
     									   //alert("服务请求错误:"+ errorThrown);
     									   //api.alert({msg:'服务请求错误!'});
     									   api.alert({msg:'网络异常'});
											clearTimeout(mytime);
											$(".shade").hide();
											//console.log("服务请求错误,请联系管理员【错误代码："+ xhr.status+ "】");
   									 }
									});

									}, 5000);
   				 } else {
    				    $("#loadingToast").hide();
    				    //api.alert({msg:'服务请求错误!'});
    				    api.alert({msg:'网络异常'});
    				    	//alert("服务请求错误:" + xhr.status);
    				        //console.log("服务请求错误,请联系管理员【错误代码："+errorThrown+"】");
    				}
				});

			}

	function ddInfo(){
		api.openWin({
	        name: 'ddcx',
	        url: './Invoice_ddcx.html'
        });
	}

	function qyxxgl(){
		api.openWin({
	        name: '开票 ',
	        url: './Invoice_qygl.html',
	        pageParam:{
	        	openid : openid
	        }
        });
    }
</script>
<style>
.nav{
	padding: 10px 2%;
}
.bg {
    padding: 15px 0 15px;
}


</style>

</head>

<body>
	<div id="jsheader">
      <nav id="jsnav">
          <a id="jsleft" tapmode="" onclick="api.closeWin();">
              <span>返回</span>
          </a>
          <div id="jsmiddle">
              <strong id="jstitle">极速开票</strong>
          </div>
          <a id="jsright">
            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
          </a>
      </nav>
  </div>
	<div class="paddingtop70">&nbsp;</div>
<div class="nav" style="height:18px;line-height:18px;font-size:16px;color:#666">
		<img style="width:110px;height:18px" src="">
	</div>
	<ul>
		<li class="hiSlider-item"><img id="banner1" src="../../resource/images/wap_banner2.jpg" style="width: 100%;"></li>
	</ul>
	<div style="background-color:#fff">
		<div class="weui-grids">
			<a class="weui-grid" onclick="scanQRCode()">
				<div class="weui-grid__icon">
					<img src="../../resource/images/icon_scan.png" alt="">
				</div>
				<p class="weui-grid__label">扫一扫</p>
			</a>
			<a class="weui-grid" onclick="createQrcode()">
				<div class="weui-grid__icon">
					<img src="../../resource/images/icon_qrcode.png" alt="">
				</div>
				<p class="weui-grid__label">支付</p>
			</a>
			<a class="weui-grid" onclick="qyxxgl()">
				<div class="weui-grid__icon">
					<img src="../../resource/images/icon_nav_panel.png" alt="">
				</div>
				<p class="weui-grid__label">开票</p>
			</a>
			<a class="weui-grid" onclick="ddInfo()">
				<div class="weui-grid__icon">
					<img src="../../resource/images/icon_nav_search_bar.png" alt="">
				</div>
				<p class="weui-grid__label">订单查询</p>
			</a>
			<a class="weui-grid" onclick="kpInfo()">
				<div class="weui-grid__icon">
					<img  src="../../resource/images/icon_nav_article.png" alt="">
				</div>
				<p class="weui-grid__label">开票结果</p>
			</a>

		</div>
	</div>
		<div class="shade" style="display: none;">
			<div style="border: 0 solid #A75A5A;width:320px;height:400px;border-radius:5px;left: 50%;top:45%;background-color: #fff;margin: -220px auto 0px -160px;position:fixed;">
				<div style="width:100%;padding-top:10px" align="right">
					<i class="weui-icon-cancel shade_div" style="font-weight:bold;color:#333;background-color:#fff;margin: 0 10px 10px;"></i>
				</div>
				<div id="bcTarget" class="barcodeImg" style="text-align:center;"></div>
				<div id="invoiceName" style="text-align: center;width: 100%;margin: 30px auto 30px auto;white-space:normal;"></div>
			</div>
		</div>
		<div id="loadingToast" style="display:none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">数据加载中...</p>
			</div>
		</div>
		<div class="page__ft">
<p style="margin-bottom: 6px" ><a style="color:#777;font-size:12px">四川航天金穗高技术有限公司</a><b id="bbb"></b></p>
</div>
	<!-- <div class="weui-tabbar" style="box-shadow:0 -2px 2px #aeaeae;">
        <a href="../../index.html" class="weui-tabbar__item">
            <img src="../../resource/images/icon_nav_actionSheet.png" alt="" class="weui-tabbar__icon">
            <p class="weui-tabbar__label">返回主页</p>
        </a>
	</div> -->

	<script>
	      	function kpInfo(){
        		api.openWin({
	                name: '开票结果',
	                url: './Invoice_kpxx.html'
                });
        	}

    		$(".shade_div").click(function() {
					api.confirm({
					    title: '二维码',
					    msg: '关闭二维码就不能在线支付或发票开具，你确定关闭吗？',
					    buttons: ['确定', '取消']
					}, function(ret, err){
							if(ret.buttonIndex==1){
								$(".shade").hide();
								if(mytime != null){
									clearTimeout(mytime);
								}
							}
					});
    			// if(confirm('关闭二维码就不能在线支付或发票开具，你确定关闭吗？')){
    			// 	$(".shade").hide();
    			// 	if(mytime != null){
    			// 		clearTimeout(mytime);
    			// 	}
    			// }

    		});

	</script>
</body>
</html>
